<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title><!--{if isset($article_array)}-->修改<!--{else}-->新增<!--{/if}-->文章</title>
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">

        <h2 style="" class="tal">正在操作：<!--{if isset($article_array)}-->修改<!--{else}-->新增<!--{/if}-->文章</h2>

        <div class="items2">

            <div>
                <form class="form-horizontal" id="article_form" onsubmit="return false;">

                    <input type="hidden" id="article_id" name="article_id" value="<!--{$article_array.article_id|default:0}-->">

                    <div class="form-group" id="ifChecked_1">
                        <label class="col-sm-3 control-label" for="article_title">
                            <span class="red">*</span>
                            文章标题：
                        </label>
                        <div class="col-sm-9">

                            <input type="text" class="form-control w300" id="article_title" name="article_title" maxlength="200" size="40" style="ime-mode:active" autocomplete="off" value="<!--{$article_array.article_title|default:''}-->">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label"> 新闻标题图片：</label>
                        <div class="col-sm-9">
                            <button type="button" class="btn btn-default" id="update_logo">点击新闻标题图片</button>
                            <div id="logo_img_box" style="<!--{if empty($article_array.article_pic)}-->display: none;<!--{/if}-->margin-top: 5px;">
                                <img src="<!--{$article_array.article_pic_show|default:''}-->">
                            </div>
                            <input type="hidden" name="article_pic" id="article_pic" value="<!--{$article_array.article_pic|default:''}-->" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="category_id">
                            <span class="red">*</span>
                            文章分类：
                        </label>
                        <div class="col-sm-9">
                            <select class="form-control w150" id="category_id" name="category_id" size="1" >
                                <option value="">请选择</option>
                                <!--{if isset($category_array)}-->
                                <!--{foreach from=$category_array item=cate}-->
                                <option value="<!--{$cate.category_id}-->" <!--{if isset($article_array) && $article_array.article_category_id == $cate.category_id}-->selected<!--{/if}--> ><!--{$cate.category_title}--></option>
                                <!--{/foreach}-->
                                <!--{/if}-->
                            </select>
                        </div>
                    </div>

                    <div class="form-group" id="ifChecked_2">
                        <label class="col-sm-3 control-label" for="article_summary">
                            文章摘要：
                        </label>
                        <div class="col-sm-9">
                            <textarea class="form-control" style="width:350px;height: 100px;" id="article_summary" name="article_summary"><!--{$article_array.article_summary|default:''}--></textarea>
                        </div>
                    </div>

                    <div class="form-group" id="ifChecked_1">
                        <label class="col-sm-3 control-label" for="article_link">
                            <span class="red">*</span>
                            外部链接：
                        </label>
                        <div class="col-sm-9">

                            <input type="text" class="form-control w500" id="article_link" name="article_link" maxlength="200" value="<!--{$article_array.article_link|default:''}-->">
                            <span class="help-block">外部链接和描述内容必须填写一个</span>
                        </div>
                    </div>

                    <div style=" margin-top:8px;">
                        <div>
                            <textarea name="description" id="description" style="width:100%;height:400px;visibility:hidden;"><!--{$article_array.description|default:''}--></textarea>
                        </div>
                    </div>

                </form>
            </div>

        </div>
    </div>

    <div class="bottom_fixbox">
        <div class="tac popup-footer">
            <input type="button" value="保存文章" onclick="article.check();" class="btn btn-success">&nbsp;&nbsp;&nbsp;
            <input type="button" value="关闭" onclick="E.closeWindows();" class="btn btn-default">
        </div>
    </div>
    <!--{include file='comm/footer.tpl'}-->

</div>

<script type="text/javascript">

    window.editor = KindEditor.create("#description");

    var article = {

        article_id: <!--{$article_array.article_id|default:0}-->,

        //检查数据
        check: function() {
            editor.sync();
            this.dt = E.getFormValues("article_form");
            var error_msg = "";
            if (this.dt.article_title == "")
                error_msg += "请填写文章标题<br />";

            if (this.dt.category_id == "")
                error_msg += "请填选择文章分类<br />";

            if (E.isEmpty(this.dt.article_link) && E.isEmpty(this.dt.description)){
                error_msg += "请填写外部链接或者描述内容<br />";
            }
            if (error_msg != "")
                E.alert(error_msg);
            else
                E.confirm("您确认要<!--{if $userFlg == 2}-->添加<!--{else}-->修改<!--{/if}-->文章信息吗？", "article.add");
        },

        //保存文章信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/content/articles.ajax?operFlg=100&act=edit",
                    dataType: "JSON",
                    data: this.dt,
                    success: function( result_obj ) {
                if (result_obj.code == 200) {
                    E.opener("article.load");
                    if (article.article_id == 0)
                        E.alert(result_obj.message, 2, "E.refresh");
                    else
                        E.alert(result_obj.message, 2, "E.closeWindows");
                } else {
                    E.alert(result_obj.message);
                }
            }
        });
    }
}



KindEditor.ready(function(K) {

    var kindEditor_upload = K.editor({
        allowFileManager : true,
        uploadJson: '/framework/kindeditor/php/upload_json.php?act=system'
    });

    $(document).on('click', '#update_logo', function() {

        kindEditor_upload.loadPlugin('image', function() {
            kindEditor_upload.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url) {
                    $('#logo_img_box').html('<img src="' + url + '"> <a href="javascript: void(0);" id="del_log_img"></a>').show();
                    $('#article_pic').val(url);
                    kindEditor_upload.hideDialog();

                }
            });
        });

    });

});



</script>

</body>

</html>